<template>
	<view class="msg-container content">
		<ms-navbar></ms-navbar>
		<view class="n-title">今日资讯</view>
		<view class="news">
		  <view
		    class="new"
		    v-for="(m, index) in msgs"
		    :key="index"
		    @click="handleDetail(m)"
		  >
		    <view class="n-txt">{{ m.title }}</view>
		    <view class="n-info">
		      <view class="agent">{{ m.mediaName }}</view>
		      <view class="date">{{ m.showTime }}</view>
		    </view>
		  </view>
		</view>
	</view>
</template>

<script>
	import {getMessageList} from '../../api/new.js'
	import store from '../../store/index.js';
	export default {
		data() {
			return {
				msgs:[]
			};
		},
		methods:{
			handleDetail(n) {
			  uni.navigateTo({ url: `/pages/new/new?newObj=${JSON.stringify(n)}` });
			},
		},
		created() {
			console.log('message begin');
			getMessageList().then(res=>{
				this.msgs = res
				console.log('list:',this.msgs);
			})
		},
		onTabItemTap() {
			let {route} = getCurrentPages()[0]
			switch (route){
				case 'pages/message/message':
					store.commit('setNavTitle','资讯')
					break;
				case 'pages/option/option':
					store.commit('setNavTitle','自选')
					break;
				case 'pages/market/market':
					store.commit('setNavTitle','行情')
					break;
				default:
					break;
			}
		},
	}
</script>

<style lang="scss">
.msg-container{
	padding-top: 20rpx;
	.n-title {
	  width: fit-content;
	  font-size: 40rpx;
	  font-weight: bold;
	  border-bottom: 4rpx solid rgba(#cb473a, 0.5);
	}
	.news {
	  .new {
	    margin: 20rpx 0;
	    border-bottom: 2rpx solid #d5d5d5;
	    padding: 10rpx 0;
	    .n-info {
	      font-size: 24rpx;
	      color: #d5d5d5;
	      display: flex;
	      justify-content: space-between;
	      margin-top: 10rpx;
	    }
	  }
	}
}
</style>
